home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / lang / c--c0202 / string.h-- < prev    next >
Encoding:
Text File  |  1994-09-11  |  6.5 KB  |  287 lines

  1. /*
  2.     SPHINX Programming (C) 1993.
  3.     TITLE:  STRING.H--
  4.     DESCRIPTION:  This file contains a collection of procedures for working
  5.                   with 0 terminating strings.
  6.     LAST MODIFIED:  11 Sept 1994
  7.     PROCEDURES DEFINED IN THIS FILE:
  8.         : word passtr(cstring_address,passtring_address)
  9.         : word PASSTR( , , , ,cstringoffset,passtringoffset)
  10.         : void strcat(deststring,sourcestring)
  11.         : void STRCAT( , , , ,deststring,sourcestring)
  12.         : char strcmp(string1,string2)
  13.         : char STRCMP(string1,string2)
  14.         : void strcpy(dest_string,source_string)
  15.         : void STRCPY( , , , ,dest_string,source_string)
  16.         : void STR_DOWN(string_address)
  17.         : word STRLEN(string_address)
  18.         : void strpas(passtring_address,cstring_address)
  19.         : void STRPAS( , , , ,passtring_address,cstring_address)
  20.         : void STR_UP(string_address)
  21.     NOTES:
  22.          In the future, add the following REG procedures for string handling:
  23.              STRWORD(number,string);
  24.              STRINT(number,string);
  25.              STRDIGITS STRWORD STRINT STRBYTE STRCHAR
  26.              STRPOS STRCAPS STRLOWS STRSTR STRINSERT STRDELETE
  27.              PASLEN PASCPY PASCAT PASCMP
  28. */
  29.  
  30.  
  31. : void STR_UP ()  /* AX = address of string */
  32. /* Converts all lower case letters in a string to upper case.
  33. */
  34. {
  35. BX = AX;
  36. BX--;
  37. do {BX++;
  38.     IF( DSBYTE[BX] >= 'a' )
  39.         IF( DSBYTE[BX] <= 'z' )
  40.             DSBYTE[BX] -= 'a' - 'A';
  41.     } while( DSBYTE[BX] != 0 );
  42. }
  43. /* returns:  AX,BX = undefined
  44. */
  45.  
  46.  
  47. : void STR_DOWN ()  /* AX = address of string */
  48. /* Converts all upper case letters in a string to lower case.
  49. */
  50. {
  51. BX = AX;
  52. BX--;
  53. do {BX++;
  54.     IF( DSBYTE[BX] >= 'A' )
  55.         IF( DSBYTE[BX] <= 'Z' )
  56.             DSBYTE[BX] += 'a' - 'A';
  57.     } while( DSBYTE[BX] != 0 );
  58. }
  59. /* returns:  AX,BX = undefined
  60. */
  61.  
  62.  
  63. : word passtr (word cstringoffset,passtringoffset)
  64. /* copies a pascal type string to a C type (0 terminating) string.
  65. */
  66. {ES = DS;
  67. DI = cstringoffset;
  68. SI = passtringoffset;
  69. $LODSB                                       
  70. AH = 0;
  71. IF( AL > 0 )
  72.     {CX = AX;
  73.     $REPZ                                       
  74.     $MOVSB
  75.     }
  76. DSBYTE[DI] = 0;                                       
  77. }                                 
  78. /* RETURNS:  AX = length of the string, not including 0 terminator.
  79.              DI,SI = undefined
  80.              CX = 0
  81.              ES = DS
  82. */
  83.  
  84.  
  85. : word PASSTR ()       /* DI = cstringoffset, SI = passtringoffset */
  86. /* copies a pascal type string to a C type (0 terminating) string.
  87. */
  88. {ES = DS;
  89. $LODSB                                       
  90. AH = 0;
  91. IF( AL > 0 )
  92.     {CX = AX;
  93.     $REPZ                                       
  94.     $MOVSB
  95.     }
  96. DSBYTE[DI] = 0;                                       
  97. }                                 
  98. /* RETURNS:  AX = length of the string, not including 0 terminator.
  99.              DI,SI = undefined
  100.              CX = 0
  101.              ES = DS
  102. */
  103.  
  104.  
  105. : void strpas (word passtringoffset,cstringoffset)
  106. /* Copies and converts a 0 terminating string to a pascal type string.
  107. */
  108. {
  109. ES = DS;
  110. SI = cstringoffset;
  111. DI = passtringoffset;
  112. BX = DI;
  113. CL = 0;
  114. DI++;
  115. HERE:
  116.     $LODSB
  117.     $CMP AL,00                              
  118.     $JZ    DOWN                               
  119.     $STOSB                                       
  120.     CL++;
  121.     $JMP HERE
  122. DOWN:
  123. DSBYTE[BX] = CL;
  124. }
  125. /* RETURNS:  ES = DS
  126.              AX,BX,CX,DI,SI = undefined
  127. */
  128.  
  129.  
  130. : void STRPAS ()   /* DI = passtringoffset, SI = cstringoffset */
  131. /* Copies and converts a 0 terminating string to a pascal type string.
  132. */
  133. {
  134. ES = DS;
  135. BX = DI;
  136. CL = 0;
  137. DI++;
  138. HERE:
  139.     $LODSB
  140.     $CMP AL,00                              
  141.     $JZ    DOWN                               
  142.     $STOSB                                       
  143.     CL++;
  144.     $JMP HERE
  145. DOWN:
  146. DSBYTE[BX] = CL;
  147. }
  148. /* RETURNS:  ES = DS
  149.              AX,BX,CX,DI,SI = undefined
  150. */
  151.  
  152.  
  153. : word STRLEN ()    /* AX = address of string */
  154. /* Determines the length of a 0 terminating string.
  155. */
  156. {
  157. BX = AX;
  158. BX--;
  159. do {BX++;
  160.     } while( DSBYTE[BX] != 0 );
  161. BX -= AX;
  162. AX = BX;
  163. }
  164. /* RETURNS:  AX = BX = length of string, not including 0 terminator.
  165. */
  166.  
  167.  
  168. : void strcpy (word dest_string,source_string)
  169. /* Copies a a 0 terminating string.
  170. */
  171. {
  172. ES = DS;
  173. SI = source_string;
  174. DI = dest_string;
  175. do {
  176.     $LODSB                                       
  177.     $STOSB                                       
  178.     } while( AL != 0 );
  179. }
  180. /* RETURNS:  ES = DS
  181.              AX,DI,SI = undefined
  182. */
  183.  
  184.  
  185. : void STRCPY ()    /* DI = dest_string, SI = source_string */
  186. /* Copies a a 0 terminating string.
  187. */
  188. {
  189. ES = DS;
  190. do {
  191.     $LODSB                                       
  192.     $STOSB                                       
  193.     } while( AL != 0 );
  194. }
  195. /* RETURNS:  ES = DS
  196.              AX,DI,SI = undefined
  197. */
  198.  
  199.  
  200. : char strcmp (word string1,string2)
  201. /* Compares two 0 terminating strings.
  202. */
  203. {
  204. SI = string1;
  205. BX = string2;
  206. BX--;
  207. TOP:
  208.     BX++;
  209.     $LODSB
  210.     $CMP AL,0
  211.     $JE HERE
  212.     $CMP DSBYTE[BX],AL
  213.     $JE TOP
  214. HERE:
  215. AL -= DSBYTE[BX];
  216. }
  217. /* RETURNS:  AL = 0 if the strings are equal
  218.              AL > 0 if string 1 is greater than string 2
  219.              AL < 0 if string 2 is greater than string 1
  220.              BX,SI = undefined
  221. */
  222.  
  223.  
  224. : char STRCMP ()   /* AX = string1, BX = string2 */
  225. /* Compares two 0 terminating strings.
  226. */
  227. {
  228. SI = AX;
  229. BX--;
  230. TOP:
  231.     BX++;
  232.     $LODSB
  233.     $CMP AL,0
  234.     $JE HERE
  235.     $CMP DSBYTE[BX],AL
  236.     $JE TOP
  237. HERE:
  238. AL -= DSBYTE[BX];
  239. }
  240. /* RETURNS:  AL = 0 if the strings are equal
  241.              AL > 0 if string 1 is greater than string 2
  242.              AL < 0 if string 2 is greater than string 1
  243.              BX,SI = undefined
  244. */
  245.  
  246.  
  247. : void strcat (word deststring,sourcestring)
  248. /* Copies source string on to the end of deststring.
  249. */
  250. {
  251. ES = DS;
  252. SI = sourcestring;
  253. DI = deststring;
  254. DI--;
  255. do {DI++;
  256.     } while( DSBYTE[DI] != 0 );
  257. do {
  258.     $LODSB                                       
  259.     $STOSB                                       
  260.     } while( AL != 0 );
  261. }
  262. /* RETURNS:  AL = 0
  263.              ES = DS
  264.              DI,SI,CX = undefined
  265. */
  266.  
  267.  
  268. : void STRCAT ()     /* DI = deststring,  SI = sourcestring */
  269. /* Copies source string on to the end of deststring.
  270. */
  271. {
  272. ES = DS;
  273. DI--;
  274. do {DI++;
  275.     } while( DSBYTE[DI] != 0 );
  276. do {
  277.     $LODSB                                       
  278.     $STOSB                                       
  279.     } while( AL != 0 );
  280. }
  281. /* RETURNS:  AL = 0
  282.              ES = DS
  283.              DI,SI,CX = undefined
  284. */
  285.  
  286.  
  287. /* end of STRING.H-- */